import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // {
    //   path: '/',
    //   name: 'home',
    //   component: HomeView
    // },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue')
    // },
    {
      path: '/',
      name: 'LoginView',
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/Main',
      name: 'MainView',
      component: () => import('../views/MainView.vue'),
      children: [
        {
          path: '/UserViews/UserList',
          name: 'UserList',
          component: () => import('../views/UserViews/UserListView.vue')
        },
        {
          path: '/UserViews/LogList',
          name: 'LogList',
          component: () => import('../views/UserViews/LogListView.vue')
        },
        {
          path: '/UserViews/RoleList',
          name: 'RoleList',
          component: () => import('../views/UserViews/RoleListView.vue')
        },
        {
          path: '/ProductionManagement/BomManage',
          name: 'BomManage',
          component: () => import('../views/ProductionManagement/BomManageView.vue')
        },
        {
          path: '/ProductionManagement/MaterialNeed',
          name: 'MaterialNeed',
          component: () => import('../views/ProductionManagement/MaterialNeedView.vue')
        },
        {
          path: '/logicflowYang/YSlogicflowBpmn',
          name: 'YSlogicflowBpmn',
          component: () => import('../views/logicflowYang/YSlogicflowBpmnView.vue')
        },
        {
          path: '/logicflowYang/YSlogicflowCustom',
          name: 'YSlogicflowCustom',
          component: () => import('../views/logicflowYang/YSlogicflowCustomView.vue')
        },
        {

          path: '/ProductManagement/ProductCategoryView',
          name: 'ProductCategoryView',
          component: () => import('../views/ProductManagement/ProductCategoryView.vue')
        },
        {

          path: '/ProductManagement/ProductInfoView',
          name: 'ProductInfoView',
          component: () => import('../views/ProductManagement/ProductInfoView.vue')
        },
        {
          path: '/SalesManagement/SalesOrder',
          name: 'SalesOrder',
          component: () => import('../views/SalesManagement/SalesOrder.vue')
        },
        {
          path: '/SalesManagement/SalesOutbound',
          name: 'SalesOutbound',
          component: () => import('../views/SalesManagement/SalesOutbound.vue')
        },
        {
          path: '/SalesManagement/SalesReturn',
          name: 'SalesReturn',
          component: () => import('../views/SalesManagement/SalesReturn.vue')
        },
        {
          path: '/SalesManagement/Homepage',
          name: 'Homepage',
          component: () => import('../views/SalesManagement/Homepage.vue')
        },
        {
          path: '/RequisitionViews/RequisitionList',
          name: 'RequisitionList',
          component: () => import('../views/RequisitionViews/RequisitionList.vue')
        },
        {
          path: '/RequisitionViews/PurchaseOrderList',
          name: 'PurchaseOrderList',
          component: () => import('../views/RequisitionViews/PurchaseOrderList.vue')
        },
        {
          path: '/BasicInformationViews/SupplierList',
          name: 'SupplierList',
          component: () => import('../views/BasicInformationViews/SupplierList.vue')
        },
        {
          path: '/StashManagement/StashWarehousing',
          name: 'StashWarehousing',
          component: () => import('../views/StashManagement/Warehousing/StashWarehousing.vue')
        },
        {
          path: '/StashManagement/AddWarehousing',
          name: 'AddWarehousing',
          component: () => import('../views/StashManagement/Warehousing/AddWarehousing.vue')
        },
        {
          path: '/StashManagement/UpdateWarehousing',
          name: 'UpdateWarehousing',
          component: () => import('../views/StashManagement/Warehousing/UpdateWarehousing.vue')
        },
        {
          path: '/StashManagement/CopyAddWarehousing',
          name: 'CopyAddWarehousing',
          component: () => import('../views/StashManagement/Warehousing/CopyAddWarehousing.vue')
        },
        {
          path: '/StashManagement/LookWarehousing',
          name: 'LookWarehousing',
          component: () => import('../views/StashManagement/Warehousing/LookWarehousing.vue')
        },
        {
          path: '/StashManagement/StashOutboundView',
          name: 'StashOutboundView',
          component: () => import('../views/StashManagement/OutboundView/StashOutboundView.vue')
        },
        {
          path: '/StashManagement/AddOutboundView',
          name: 'AddOutboundView',
          component: () => import('../views/StashManagement/OutboundView/AddOutboundView.vue')
        },
        {
          path: '/BasicInformationViews/CustomerList',
          name: 'CustomerList',
          component: () => import('../views/BasicInformationViews/CustomerList.vue')
        },
        {
          path: '/BasicInformationViews/WarehouseList',
          name: 'WarehouseList',
          component: () => import('../views/BasicInformationViews/WarehouseList.vue')
        },
        {
          path: '/ProductionManagement/ProductiveTaskView',
          name: 'ProductiveTaskView',
          component: () => import('../views/ProductionManagement/ProductiveTaskView.vue')
        },
        {
          path: '/ProductionManagement/AddProductiveTask',
          name: 'AddProductiveTask',
          component: () => import('../views/ProductionManagement/AddProductiveTask.vue')
        }

      ]
    },




  ]
})
// 导航守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = localStorage.getItem("isAuthenticated") === 'true';

  if (to.name !== 'LoginView' && !isAuthenticated) {
    next({ name: 'LoginView' }); // 未认证用户重定向到登录页面
  } else {
    next(); // 已认证用户或访问登录页的情况下，继续
  }
});
export default router
